#include "pageswitchbutton.h"
#include "util.h"

PageSwitchButton::PageSwitchButton(QWidget* parent)
    : QPushButton{parent}
{
    // 设置按钮的大小
    this->setFixedSize(QSize(48, 46));

    btnImage = new QLabel(this);
    btnImage->setGeometry((48-24)/2, 0, 24, 24);

    btnTittle = new QLabel(this);
    btnTittle->setGeometry(0, 30, 49, 16);
    btnTittle->setAlignment(Qt::AlignCenter);

    // 去掉按钮的边框
    setStyleSheet("border:none;");
}

void PageSwitchButton::setImageAndText(const QString &imagePath, const QString &text, int pageId)
{
    this->setImage(imagePath);
    this->btnTittle->setText(text);
    this->pageId = pageId;
}

void PageSwitchButton::setTextColor(const QString &textColor)
{
    btnTittle->setStyleSheet("font-family : 微软雅黑;"
                             "font-size : 12px;"
                             "font-weight : bold;"
                             "color : " + textColor + ";");
}

void PageSwitchButton::setImage(const QString &imagePath)
{
    btnImage->setPixmap(QPixmap(imagePath));
}

int PageSwitchButton::getPageId() const
{
    return pageId;
}

void PageSwitchButton::mousePressEvent(QMouseEvent *event)
{
    emit switchPage(pageId);
    LOG() << pageId << "按钮被点击了";
}
